package com.bwie.bwedu.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.bwie.bwedu.application.App;

/**
 * Created by gateway on 2016/7/6.
 */
public class ShareprefreceUtils {
    public static final String PREFRECE_NAME="login_info";
    public static final String APP_KEY_PWD="app_key_pwd";
    public static final String  APP_SETUP_PROGARD="app_setup_progard";


    public static void write(String name,String value){
//        SharedPreferences sp = context == null ? null: context.getSharedPreferences(PREFRECE_NAME,Context.MODE_PRIVATE);

        SharedPreferences sp = App.getContext().getSharedPreferences(PREFRECE_NAME,Context.MODE_PRIVATE);
//        ToastUtils.getToast("保存界面");
        if ( sp!= null && !TextUtils.isEmpty(name)) {
            SharedPreferences.Editor edit = sp.edit();
            edit.putString(name, value);
            edit.commit();
//            ToastUtils.getToast("保存成功");
        }
    }

    public static String readfromExternl(String name,String defaultValue){

        SharedPreferences sp =App.getContext().getSharedPreferences(PREFRECE_NAME,Context.MODE_PRIVATE);
//        ToastUtils.getToast(sp==null?defaultValue:sp.getString(name,defaultValue));
        return sp==null ? defaultValue:sp.getString(name,defaultValue);
    }

    public static void write(String name,boolean value){
        SharedPreferences sp= App.getContext().getSharedPreferences(PREFRECE_NAME,Context.MODE_PRIVATE);
        if(sp!=null){
            SharedPreferences.Editor edit = sp.edit();
            edit.putBoolean(name, value);
            edit.commit();
        }
    }
    public static boolean readFromExternel(String name,boolean defaultvalue){
        SharedPreferences sp = App.getContext().getSharedPreferences(PREFRECE_NAME,Context.MODE_PRIVATE);
        return  sp==null?defaultvalue:sp.getBoolean(name,defaultvalue);
    }
    public static void clear(){
        SharedPreferences sp = App.getContext().getSharedPreferences(PREFRECE_NAME,Context.MODE_PRIVATE);
        sp.edit().clear().commit();
    }
}
